//
//  ReplyView.m
//  text2
//
//  Created by edz on 2017/11/1.
//  Copyright © 2017年 edz. All rights reserved.
//

#import "ReplyView.h"

@interface ReplyView() <UITextViewDelegate>

@property (weak, nonatomic) IBOutlet UITextView *replyTextView;


@end

@implementation ReplyView

-(void)awakeFromNib {
    [super awakeFromNib];
    self.replyTextView.delegate = self;
}

#pragma mark -取消和确认事件
- (IBAction)didCancelBtn:(id)sender {
    [self removeFromSuperview];
}

- (IBAction)didSuerBtn:(id)sender {
    if ([self.replyTextView.text isEqualToString:@"输入内容"]) {
    }else {
        self.textFieldBlock(_replyTextView.text);
    }
    
    [self removeFromSuperview];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.replyTextView resignFirstResponder];
}



#pragma mark - 自定义构建方法
-(instancetype)initReplyView {
    self = [[[NSBundle mainBundle]loadNibNamed:@"ReplyView" owner:nil options:nil]lastObject];
    self.frame = [UIScreen mainScreen].bounds;
    
    [[UIApplication sharedApplication].keyWindow addSubview:self];
    return self;
}

#pragma mark - 处理键盘占位问题
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(textView.text.length < 1){
        textView.text = @"输入内容";
        textView.textColor = [UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1];
    }
    
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([textView.text isEqualToString:@"输入内容"]){
        textView.text=@"";
        textView.textColor=[UIColor colorWithRed:204.0/255.0 green:204.0/255.0 blue:204.0/255.0 alpha:1];
    }
    
}

- (void)textViewDidChange:(UITextView *)textView {
    if(textView.text.length > 1){
        textView.textColor = [UIColor blackColor];
    }
}




@end
